package com.woniuxueyuan.Producer;

import com.woniuxueyuan.util.RabbitmqConst;
import org.springframework.amqp.AmqpException;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessagePostProcessor;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
public class DelayProducer {
  @Resource
    private RabbitTemplate rabbitTemplate;
    public void send(String msg,String routeKey,Integer TTL){

        rabbitTemplate.convertAndSend(RabbitmqConst.DELAY_EXCHANGE, routeKey, msg, new MessagePostProcessor() {
            @Override
            public Message postProcessMessage(Message message) throws AmqpException {
                message.getMessageProperties().setDelay(TTL);//设置消息的TTL时间，单位是毫米
                return message;
            }
        });
    }
}
